//
//  BaseWKWebView.m
//  lvfj
//
//  Created by lvfeijun on 2021/9/3.
//  Copyright © 2021 Goudu KuaiEx Technology(Shenzhen)Co.,ltd. All rights reserved.
//

#import "BaseWKWebView.h"

@implementation BaseWKWebView

- (void)setVideoMod:(HQHomeHotModel *)videoMod
{
    _videoMod = videoMod;
    
    self.titleLable.text = videoMod.title;
    self.timeLable.text = videoMod.sourceTimeStr;
    self.agreeBut.selected = videoMod.isAgree;
    self.descriptionLable.text = videoMod.descrip;
    [self.descriptionLable hq_changeWithLineSpace:8 WordSpace:0.78];
    
    self.hq_height = self.moreLookLable.hq_y;
    
    NSSet *websiteDataTypes= [NSSet setWithArray:@[
        WKWebsiteDataTypeDiskCache,
        WKWebsiteDataTypeMemoryCache,
        WKWebsiteDataTypeOfflineWebApplicationCache
    ]];
    //清除所有的web信息
    //NSSet *websiteDataTypes = [WKWebsiteDataStore allWebsiteDataTypes];
    NSDate *dateFrom = [NSDate dateWithTimeIntervalSince1970:0];
    [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:websiteDataTypes modifiedSince:dateFrom completionHandler:^{
        
    }];
    
    NSString *str0 = @"<html><head><meta name=\"viewport\" content=\"width=%f,initial-scale=1.0,maximum-scale=1.0,user-scalable=0\" />\n<link type=\"text/css\" href=\"https://oss-hqwx-edu24ol.oss-cn-beijing.aliyuncs.com/jianzhujie/css/article.reset.css\" rel=\"stylesheet\"><style>\nimg {max-width:100%;height:auto;}\n table {\nmax-width:100%;height:auto;}</style>\n<base href=\"https://www.jianzhuj.cn\"></head>\n<body>";
    //<base href=\"https://www.jianzhuj.cn\">
    
    NSString *str1 = @"</body>\n</html>";
    NSString *string = NSStringFormat(@"%@%@%@",str0,videoMod.content,str1) ;
    /**
     //js注入
     
     NSString *str2 = @"\"<script type='text/javascript'>"
     "window.onload = function(){\n"
     "var $img = document.getElementsByTagName('img');\n"
     "for(var p in  $img){\n"
     "var url=$img[p].getAttribute(\"src\");"
     "var httpP =  url.substr(0,5)=='http' ?(\"https://mip.jianzhuj.cn/\"+url):url;"
     "$img[p].setAttribute(\"src\",httpP);"
     "$img[p].style.width = '100%%';\n"
     "$img[p].style.height ='auto'\n"
     "}\n"
     "}"
     "</script>\"";
     NSString *string = NSStringFormat(@"%@%@%@%@",str0,videoMod.content,str2,str1) ;
     */
    
    [self.webView loadHTMLString:string baseURL:nil];
    
    
    [self.webView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.mas_offset(0);
    }];

    
    self.tipLable.hidden = !videoMod.oriStatus;
    
    if (videoMod.categoryId != 0) {
        self.moreLookLable.hidden = NO;
        self.lineV1.hidden = NO;
    } else {
        self.moreLookLable.hidden = YES;
        self.lineV1.hidden = YES;
    }
}

@end
